<template>
  <div class="cu-cell__item" :class="{ column: column }" @click="onClick">
    <div class="cell-item__title" :style="{ width: titleWidth ? titleWidth : 'auto' }">
      <span v-if="required" class="text-error">*</span>
      <span>{{ title }}</span>
    </div>
    <div v-if="$slots.default" class="flex-auto justify-end"><slot></slot></div>
    <div v-else class="flex-auto description-wrap" :class="[descriptionAlign]">
      <span v-if="description === ''" class="cell-placeholder">{{ placeholder }}</span>
      <span v-else class="cell-description">{{ description }}</span>
    </div>
    <div v-if="link"><uni-icons type="forward" size="18" color="#999"></uni-icons></div>
  </div>
</template>

<script>
export default {
  props: {
    title: [Number, String],
    titleWidth: String,
    description: {
      type: [Number, String],
      default: ''
    },
    descriptionAlign: {
      type: String,
      default: 'right'
    },
    required: {
      type: Boolean,
      default: false
    },
    column: {
      type: Boolean,
      default: false
    },
    link: {
      type: Boolean,
      default: false
    },
    placeholder: [Number, String]
  },
  data() {
    return {}
  },
  watch: {
    description: function (val) {
      // console.log(val)
    }
  },
  methods: {
    onClick() {
      this.$emit('click')
    }
  }
}
</script>

<style lang="scss" scoped>
.cu-cell__item {
  padding: 30rpx 20rpx 30rpx 0rpx;
  position: relative;
  min-height: 100rpx;
  display: flex;
  box-sizing: border-box;

  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #d5d7e3;
    height: 1rpx;
    transform: scaleY(0.5);
    transform-origin: bottom center;
  }
  .description-wrap {
    line-height: 40rpx;
    &.right {
      text-align: right;
    }
    &.left {
      text-align: left;
    }
  }
  .cell-item__title {
    font-size: 30rpx;
    line-height: 40rpx;
    color: #333333;
    font-weight: 400;
    flex-shrink: 0;
    max-width: 50vw;
  }

  .flex-auto {
    padding-left: 20rpx;
  }

  .text-error {
    display: inline-block;
    width: 12rpx;
    color: #dd524d;
  }

  .cell-slot {
    padding: 0;
  }

  .text-right {
    text-align: right;
  }

  .cell-placeholder {
    color: #bbbbbb;
    font-size: 28rpx;
  }
  &.column {
    flex-direction: column;
    .cell-item__title {
      margin-bottom: 12rpx;
    }
    .flex-auto {
      padding-left: 0rpx;
    }
  }
}
</style>
